home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / ClipPanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  10KB  |  382 lines

  1. /*
  2. **    ClipPanel.c
  3. **
  4. **    Editing panel for clipboard configuration
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_UNIT,GAD_CHARDELAY,GAD_LINEDELAY,GAD_PROMPT,GAD_SENDTIMEOUT,GAD_PACING,GAD_PREFIX,GAD_SUFFIX,
  13.         GAD_USE,GAD_CANCEL,GAD_DEFAULT };
  14.  
  15. STATIC STRPTR PacingMode[7];
  16.  
  17. STATIC STRPTR __saveds
  18. ShowTime(struct Gadget *SomeGadget,WORD Level)
  19. {
  20.     return(LocaleSeconds(Level));
  21. }
  22.  
  23. STATIC struct Gadget *
  24. CreateAllGadgets(struct Configuration *Config,struct Gadget **GadgetArray,struct Gadget **GadgetList,BYTE *Default)
  25. {
  26.     struct Gadget        *Gadget;
  27.     struct NewGadget     NewGadget;
  28.     UWORD             Counter = 0;
  29.  
  30.     LocalizeString(PacingMode,MSG_CLIPPANEL_DIRECT_TXT,MSG_CLIPPANEL_KEYDELAY_TXT);
  31.  
  32.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  33.  
  34.     memset(&NewGadget,0,sizeof(struct NewGadget));
  35.  
  36.     if(Gadget = CreateContext(GadgetList))
  37.     {
  38.         LONG Width;
  39.  
  40.         SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_CLIPPANEL_UNIT_GAD,MSG_CLIPPANEL_TEXT_PACING_GAD));
  41.  
  42.         SZ_ResetMaxWidth();
  43.  
  44.         SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,PacingMode);
  45.         SZ_UpdateMaxWidth(INTEGER_KIND,NULL,20,NULL);
  46.  
  47.         Width = SZ_ResetMaxWidth();
  48.  
  49.         if(Width < 108)
  50.             Width = 108;
  51.  
  52.         SZ_SetWidth(Width);
  53.  
  54.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_UNIT_GAD);
  55.         NewGadget . ng_GadgetID        = Counter;
  56.  
  57.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  58.             SZ_Adjust,    TRUE,
  59.             SZ_AutoWidth,    TRUE,
  60.  
  61.             GTIN_MaxChars,    3,
  62.             GTIN_Number,    Config -> ClipConfig -> ClipboardUnit,
  63.         TAG_DONE);
  64.  
  65.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_CHAR_DELAY_GAD);
  66.         NewGadget . ng_GadgetID        = Counter;
  67.  
  68.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  69.             SZ_Adjust,        TRUE,
  70.             SZ_AutoWidth,        TRUE,
  71.             SZ_AlignExtra,        TRUE,
  72.  
  73.             GTSL_Min,        0,
  74.             GTSL_Max,        10 * 100,
  75.             GTSL_Level,        Config -> ClipConfig -> CharDelay,
  76.             GTSL_MaxLevelLen,    7,
  77.             GTSL_LevelFormat,    "%s s",
  78.             GTSL_DispFunc,        ShowTime,
  79.             PGA_Freedom,        LORIENT_HORIZ,
  80.             GA_Immediate,        TRUE,
  81.             GA_RelVerify,        TRUE,
  82.         TAG_DONE);
  83.  
  84.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_LINE_DELAY_GAD);
  85.         NewGadget . ng_GadgetID        = Counter;
  86.  
  87.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  88.             SZ_Adjust,        TRUE,
  89.             SZ_AutoWidth,        TRUE,
  90.  
  91.             GTSL_Min,        0,
  92.             GTSL_Max,        10 * 100,
  93.             GTSL_Level,        Config -> ClipConfig -> LineDelay,
  94.             GTSL_MaxLevelLen,    7,
  95.             GTSL_LevelFormat,    "%s s",
  96.             GTSL_DispFunc,        ShowTime,
  97.             PGA_Freedom,        LORIENT_HORIZ,
  98.             GA_Immediate,        TRUE,
  99.             GA_RelVerify,        TRUE,
  100.         TAG_DONE);
  101.  
  102.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_LINE_PROMPT_GAD);
  103.         NewGadget . ng_GadgetID        = Counter;
  104.  
  105.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  106.             SZ_Adjust,    TRUE,
  107.             SZ_AutoWidth,    TRUE,
  108.  
  109.             GTST_MaxChars,    255,
  110.             GTST_String,    Config -> ClipConfig -> LinePrompt,
  111.         TAG_DONE);
  112.  
  113.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_SEND_TIMEOUT_GAD);
  114.         NewGadget . ng_GadgetID        = Counter;
  115.  
  116.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  117.             SZ_Adjust,        TRUE,
  118.             SZ_AutoWidth,        TRUE,
  119.  
  120.             GTSL_Min,        0,
  121.             GTSL_Max,        10 * 100,
  122.             GTSL_Level,        Config -> ClipConfig -> SendTimeout,
  123.             GTSL_MaxLevelLen,    7,
  124.             GTSL_LevelFormat,    "%s s",
  125.             GTSL_DispFunc,        ShowTime,
  126.             PGA_Freedom,        LORIENT_HORIZ,
  127.             GA_Immediate,        TRUE,
  128.             GA_RelVerify,        TRUE,
  129.         TAG_DONE);
  130.  
  131.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_TEXT_PACING_GAD);
  132.         NewGadget . ng_GadgetID        = Counter;
  133.  
  134.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  135.             SZ_Adjust,    TRUE,
  136.             SZ_AutoWidth,    TRUE,
  137.  
  138.             GTCY_Labels,    PacingMode,
  139.             GTCY_Active,    Config -> ClipConfig -> PacingMode,
  140.         TAG_DONE);
  141.  
  142.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_PASTE_PREFIX_GAD);
  143.         NewGadget . ng_GadgetID        = Counter;
  144.  
  145.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  146.             SZ_Adjust,    TRUE,
  147.             SZ_AutoWidth,    TRUE,
  148.             SZ_AlignExtra,    TRUE,
  149.  
  150.             GTST_MaxChars,    79,
  151.             GTST_String,    Config -> ClipConfig -> InsertPrefix,
  152.         TAG_DONE);
  153.  
  154.         NewGadget . ng_GadgetText    = LocaleString(MSG_CLIPPANEL_PASTE_SUFFIX_GAD);
  155.         NewGadget . ng_GadgetID        = Counter;
  156.  
  157.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  158.             SZ_Adjust,    TRUE,
  159.             SZ_AutoWidth,    TRUE,
  160.  
  161.             GTST_MaxChars,    79,
  162.             GTST_String,    Config -> ClipConfig -> InsertSuffix,
  163.         TAG_DONE);
  164.  
  165.         SZ_ResetMaxWidth();
  166.  
  167.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  168.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  169.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_DEFAULT_GAD),0,NULL);
  170.  
  171.         SZ_SetWidth(SZ_ResetMaxWidth());
  172.  
  173.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  174.         NewGadget . ng_GadgetID        = Counter;
  175.         NewGadget . ng_Flags        = 0;
  176.  
  177.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  178.             SZ_AlignExtra,    TRUE,
  179.             SZ_Adjust,    TRUE,
  180.             SZ_AutoWidth,    TRUE,
  181.             SZ_AlignLeft,    TRUE,
  182.             SZ_AlignBottom,    TRUE,
  183.         TAG_DONE);
  184.  
  185.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  186.         NewGadget . ng_GadgetID        = Counter;
  187.  
  188.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  189.             SZ_Adjust,    TRUE,
  190.             SZ_AutoWidth,    TRUE,
  191.             SZ_AlignRight,    TRUE,
  192.         TAG_DONE);
  193.  
  194.         if(Default)
  195.         {
  196.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_DEFAULT_GAD);
  197.             NewGadget . ng_GadgetID        = Counter;
  198.  
  199.             GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  200.                 SZ_Adjust,    TRUE,
  201.                 SZ_AutoWidth,    TRUE,
  202.                 SZ_AlignCentre,    TRUE,
  203.             TAG_DONE);
  204.         }
  205.     }
  206.  
  207.     return(Gadget);
  208. }
  209.  
  210. BYTE
  211. ClipPanel(struct Configuration *Config,BYTE *Default)
  212. {
  213.     struct Window    *PanelWindow;
  214.     struct Gadget    *GadgetList = NULL;
  215.     struct Gadget    *GadgetArray[GAD_DEFAULT + 1];
  216.  
  217.     SaveConfig(Config,PrivateConfig);
  218.  
  219.     if(CreateAllGadgets(Config,GadgetArray,&GadgetList,Default))
  220.     {
  221.         if(PanelWindow = OpenWindowTags(NULL,
  222.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  223.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  224.             WA_Width,    SZ_GetWindowWidth(),
  225.             WA_Height,    SZ_GetWindowHeight(),
  226.  
  227.             WA_Activate,    TRUE,
  228.             WA_DragBar,    TRUE,
  229.             WA_DepthGadget,    TRUE,
  230.             WA_RMBTrap,    TRUE,
  231.             WA_DepthGadget,    TRUE,
  232.             WA_CloseGadget,    TRUE,
  233.             WA_CustomScreen,Window -> WScreen,
  234.  
  235.             WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | SLIDERIDCMP | BUTTONIDCMP | INTEGERIDCMP | STRINGIDCMP | CYCLEIDCMP,
  236.  
  237.             WA_Title,    LocaleString(MSG_CLIPPANEL_CLIP_SETTINGS_TXT),
  238.         TAG_DONE))
  239.         {
  240.             struct IntuiMessage    *Massage;
  241.             ULONG             IClass,Code;
  242.             struct Gadget        *Gadget;
  243.             BYTE             Terminated = FALSE;
  244.  
  245.             GuideContext(CONTEXT_CLIP);
  246.  
  247.             PushWindow(PanelWindow);
  248.  
  249.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  250.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  251.             GT_RefreshWindow(PanelWindow,NULL);
  252.  
  253.             ActiveGadget = NULL;
  254.  
  255.             ClrSignal(SIG_BREAK);
  256.  
  257.             while(!Terminated)
  258.             {
  259.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  260.                 {
  261.                     SaveConfig(PrivateConfig,Config);
  262.  
  263.                     break;
  264.                 }
  265.  
  266.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  267.                 {
  268.                     IClass    = Massage -> Class;
  269.                     Code    = Massage -> Code;
  270.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  271.  
  272.                     GT_ReplyIMsg(Massage);
  273.  
  274.                     KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  275.  
  276.                     if(IClass == IDCMP_GADGETDOWN)
  277.                     {
  278.                         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  279.                             ActiveGadget = Gadget;
  280.                     }
  281.  
  282.                     if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
  283.                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  284.  
  285.                     if(IClass == IDCMP_CLOSEWINDOW)
  286.                     {
  287.                         SaveConfig(PrivateConfig,Config);
  288.  
  289.                         Terminated = TRUE;
  290.                     }
  291.  
  292.                     if(IClass == IDCMP_MOUSEMOVE)
  293.                     {
  294.                         switch(Gadget -> GadgetID)
  295.                         {
  296.                             case GAD_CHARDELAY:
  297.  
  298.                                 Config -> ClipConfig -> CharDelay = Code;
  299.                                 break;
  300.  
  301.                             case GAD_LINEDELAY:
  302.  
  303.                                 Config -> ClipConfig -> LineDelay = Code;
  304.                                 break;
  305.                         }
  306.                     }
  307.  
  308.                     if(IClass == IDCMP_GADGETUP)
  309.                     {
  310.                         switch(Gadget -> GadgetID)
  311.                         {
  312.                             case GAD_PACING:
  313.  
  314.                                 Config -> ClipConfig -> PacingMode = Code;
  315.                                 break;
  316.  
  317.                             case GAD_CHARDELAY:
  318.  
  319.                                 Config -> ClipConfig -> CharDelay = Code;
  320.                                 break;
  321.  
  322.                             case GAD_LINEDELAY:
  323.  
  324.                                 Config -> ClipConfig -> LineDelay = Code;
  325.                                 break;
  326.  
  327.                             case GAD_SENDTIMEOUT:
  328.  
  329.                                 Config -> ClipConfig -> SendTimeout = Code;
  330.                                 break;
  331.  
  332.                             case GAD_PREFIX:
  333.  
  334.                                 ActivateGadget(ActiveGadget = GadgetArray[GAD_SUFFIX],PanelWindow,NULL);
  335.                                 break;
  336.  
  337.                             case GAD_USE:
  338.  
  339.                                 Terminated = TRUE;
  340.  
  341.                                 strcpy(Config -> ClipConfig -> InsertPrefix,    SZ_GetString(GadgetArray[GAD_PREFIX]));
  342.                                 strcpy(Config -> ClipConfig -> InsertSuffix,    SZ_GetString(GadgetArray[GAD_SUFFIX]));
  343.  
  344.                                 strcpy(Config -> ClipConfig -> LinePrompt,    SZ_GetString(GadgetArray[GAD_PROMPT]));
  345.  
  346.                                 Config -> ClipConfig -> ClipboardUnit = SZ_GetInteger(GadgetArray[GAD_UNIT]);
  347.  
  348.                                 break;
  349.  
  350.                             case GAD_CANCEL:
  351.  
  352.                                 Terminated = TRUE;
  353.  
  354.                                 SaveConfig(PrivateConfig,Config);
  355.  
  356.                                 break;
  357.  
  358.                             case GAD_DEFAULT:
  359.  
  360.                                 *Default    = TRUE;
  361.  
  362.                                 Terminated    = TRUE;
  363.  
  364.                                 break;
  365.                         }
  366.                     }
  367.                 }
  368.             }
  369.  
  370.             RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  371.  
  372.             PopWindow();
  373.  
  374.             CloseWindow(PanelWindow);
  375.         }
  376.     }
  377.  
  378.     FreeGadgets(GadgetList);
  379.  
  380.     return((BYTE)memcmp(PrivateConfig -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings)));
  381. }
  382.